package com.mentaleye.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.RolePersonBean;
import com.mentaleye.dal.dao.RolePersonDao;
import com.mentaleye.dal.model.RolePerson;
import com.mentaleye.service.RolePersonService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;
@Service
public class RolePersonServiceImpl implements RolePersonService{

	@Autowired private RolePersonDao rolePersonDao;
	@Override
	public boolean addRolePerson(RolePersonBean rolePersonBean) {
		RolePerson rolePerson = (RolePerson) ObjectUtil.transfer(rolePersonBean, RolePerson.class);
		return rolePersonDao.insertPersonToRole(rolePerson);
	}

	@Override
	public boolean deleteRolePersonById(Integer rolePersonNo,Integer roleNo,Integer personType) {
		return rolePersonDao.deletePersonFromRole(rolePersonNo,roleNo,personType);
	}

	@Override
	public boolean deleteRolePersonByList(List<Integer> ids,Integer roleNo) {
		return rolePersonDao.deletePersonFromRoleByList(ids,roleNo);
	}

	@Override
	public List<RolePersonBean> selectRolePerson(Integer rolePersonNo) {
		@SuppressWarnings("unchecked")
		List<RolePersonBean> rolePersonBeanList = ObjectUtil.transferList(rolePersonDao.queryRolePersonListByRoleNo(rolePersonNo),RolePersonBean.class);
		return rolePersonBeanList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void queryRoleTeacherByPage(CommonPage commonPage) {
		List<RolePersonBean> data = ObjectUtil.transferList(rolePersonDao.queryRolePerson(commonPage.pageToMap()),RolePersonBean.class);
		commonPage.setPageData(data);
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean addRolePersonList(List<RolePersonBean> rolePersonBeanList) {
		return rolePersonDao.insertPersonToRoleList(ObjectUtil.transferList(rolePersonBeanList, RolePerson.class));
	}

}
